package elicecn.web.struts2ext.interceptor;

import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

import elicecn.web.struts2ext.action.BaseAction;

public class MustLoginInterceptor extends AbstractInterceptor {
	private static final long serialVersionUID = -4743663318187382259L;

	@SuppressWarnings( { "unchecked" })
	public String intercept(ActionInvocation ai) throws Exception {
		Map session = ActionContext.getContext().getSession();
		if (session != null) {
			session.put("backUrl", BaseAction.getRequestUrl());
			return BaseAction.LOGIN;
		} else {
			return ai.invoke();
		}
	}

}
